home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / gnuplot / lasergnu < prev    next >
Text File  |  1993-09-15  |  5KB  |  163 lines

  1. #!/bin/csh -f
  2. #
  3. # $Id: lasergnu%v 3.50 1993/07/09 05:35:24 woo Exp $
  4. #
  5. # Print gnuplot output on an Imagen or Postscript laser printer.
  6.  
  7. set print_banner = on   # Print a banner page unless told otherwise.
  8. set input_files = ()    # the plot input command files
  9. set lpr_opts = ()       # options to lpr
  10.  
  11. # Default printer set by shell variable PRINTER.
  12. if (! $?PRINTER) then
  13.     if ($?LASER) then
  14.         set PRINTER=$LASER
  15.     else
  16.         set PRINTER="lw0"
  17.     endif
  18. endif
  19. set printer = (-P$PRINTER)
  20.  
  21. # File for plot commands, and for plot output
  22. set TMP=/tmp/plot$$
  23. set outfile=$TMP.out    # the output file
  24. onintr cleanup
  25.  
  26. # default is Imagen mode for Imagen printer; see -p option
  27. set setterm="set terminal imagen"
  28. set LANG="-Limpress"
  29.  
  30. set usage="usage: lasergnu [-Pprinter] [-b] [-p] [-t title] [-f file] ['plot command']...."
  31.  
  32. # Loop through the command-line arguments.
  33.  
  34. top:
  35.     if ($#argv > 0) then
  36.  
  37.         switch ("$argv[1]")
  38.  
  39.         case -b*:   # Do not print a banner page.
  40.         case -J*:   # Compatible with imprint.
  41.             set print_banner = off
  42.                 set lpr_opts=($lpr_opts -h)
  43.             shift argv
  44.             goto top
  45.  
  46.         case -f?*:  # Specify file containing plot commands
  47.             set input_files = ($input_files `echo $argv[1] | sed 's/^-f//'`)
  48.             shift argv
  49.             goto top
  50.  
  51.         case -f:    # Specify file containing plot commands
  52.             shift argv
  53.             if ($#argv > 0) then
  54.                 set input_files = ($input_files $argv[1])
  55.                 shift argv
  56.             else
  57.                 echo "Usage: -f file ..."
  58.                 echo "Type    lasergnu -help    for help."
  59.                 exit (1)
  60.             endif
  61.             goto top
  62.  
  63.         case -t?*:  # Specify title of plot
  64.             echo set title \""`echo $argv[1] | sed 's/^-t//'`"\" >> $TMP
  65.             shift argv
  66.             goto top
  67.  
  68.         case -t:    # Specify title of plot
  69.             shift argv
  70.             if ($#argv > 0) then
  71.                 echo set title \""$1"\" >> $TMP
  72.                 shift argv
  73.             else
  74.                 echo "Usage: -t title ..."
  75.                 echo "Type    lasergnu -help    for help."
  76.                 exit (1)
  77.             endif
  78.             goto top
  79.         case -help:
  80.             echo "$usage"
  81.             exit(1)
  82.  
  83.         case -P?*:  # Set the printer, exactly as by itroff.
  84.             set printer = $argv[1]
  85.             shift argv
  86.             goto top
  87.  
  88.         case -P:    # Set the printer, exactly as by itroff.
  89.             shift argv
  90.             if ($#argv > 0) then
  91.                 set printer = (-P$argv[1])
  92.                 shift argv
  93.             else
  94.                 echo "Usage: -P printer ..."
  95.                 echo "Type    lasergnu -help    for help."
  96.                 exit (1)
  97.             endif
  98.             goto top
  99.  
  100.                 # use impress
  101.         case -I:
  102.              echo Imagen is the default mode now
  103.              shift argv
  104.              goto top
  105.  
  106.                 # use postscript instead of impress language
  107.         case -p:
  108.              set setterm="set term postscript"
  109.              set LANG="-Lpostscript"
  110.              shift argv
  111.              goto top
  112.  
  113.         case -?*:
  114.             echo "I do not recognize option $argv[1]."
  115.             echo "$usage"
  116.             exit (1)
  117.  
  118.         default:
  119.               echo "$argv[1]"   >> $TMP
  120.             shift argv
  121.             goto top
  122.  
  123.         endsw
  124.     endif
  125.  
  126. # try to devine the printer type
  127. if ($printer =~ -Plw*) then
  128.     set setterm="set term postscript"
  129.     set LANG="-Lpostscript"
  130. endif
  131.  
  132. if ($printer =~ -Pim*) then
  133.     set setterm="set term imagen"
  134.     set LANG="-Limpress"
  135. endif
  136.  
  137. # Set up input file
  138. echo $setterm > $TMP.plt
  139. echo set output \"$outfile\" >> $TMP.plt
  140. if (-e $TMP) cat $TMP >> $TMP.plt
  141.  
  142. # If input file is specified AND command line contains plot commands, then
  143. #   do command line args first, then plot commands in input file.
  144. gnuplot $TMP.plt $input_files
  145.  
  146. if ($status == 0 && -e $outfile && ! -z $outfile) then
  147.     # The printer is whatever printer was last specified,
  148.     # or the default printer if none was specified.
  149.     if ($LANG == -Limpress) then
  150.         /usr/local/bin/ipr $LANG $printer \
  151.            -D"jobheader $print_banner" \
  152.            -D"pagereversal on" \
  153.            -D"program lasergnu" $outfile
  154.     else if ($LANG == -Lpostscript) then
  155.            lpr $lpr_opts $printer $outfile
  156.     endif
  157. else
  158.     echo "lasergnu: error in plotting or empty plot; nothing printed."
  159. endif
  160.  
  161. cleanup:
  162. rm -f $TMP* $outfile
  163.